<?php
namespace Health\Http\Controllers\Admin;

use Health\Http\Controllers\Admin\BaseController;
use Health\Models\Order;
use Illuminate\Http\Request;

class OrderController extends BaseController
{
    public function index(Request $request)
    {
        $searchData=array_map('trim', $request->only(['user_id','link_name','link_mobile','status']));
        $data['searchData']=$searchData;
        $where = [];

        //用户ID
        if (!empty($searchData['user_id'])) {
            $where[] = array('user_id', $searchData['user_id']);
        }
        //联系人
        if (!empty($searchData['link_name'])) {
            $where[] = ['link_name', 'like', '%' . $searchData['link_name'] . '%'];
        }
        //联系手机
        if (!empty($searchData['link_mobile'])) {
            $where[] = ['link_mobile', 'like', '%' . $searchData['link_mobile'] . '%'];
        }
        //状态
        if (!empty($searchData['status'])) {
            $where[] = array('status', $searchData['status']);
        }

        $data['data']=Order::where($where)->orderBy('created_at','desc')->paginate(10);
        return view('admin.order.index',$data);
    }
}